'use strict';

const uuidv1 = require('uuid/v1');

const Controller = require('egg').Controller;

class CommonController extends Controller {
    async test() {
        const { app, config, ctx } = this;
        let data = uuidv1();
        console.dir(config.HOME);
        ctx.successResult(data);
    }

    async tencentGeocoder() {
        const { ctx, service } = this;
        const { longitude, latitude } = ctx.query;

        try {
            const result = await service.wechat.geoCoder(longitude, latitude);

            if (result.success) {
                ctx.successResult(result.data);
            } else {
                ctx.errorResult(result.data);
            }
        } catch (error) {
            ctx.errorResult(error.message);
        }
    }
}

module.exports = CommonController;
